//import com.adobe.cairngorm.control.CairngormEventDispatcher;
import com.wcarmon.life.event.*;
import com.wcarmon.life.model.LifeModelLocator;
import com.wcarmon.life.vo.*;
import flash.system.*;
import mx.containers.*;
import mx.controls.*;
import mx.events.*;
import mx.managers.*;
import mx.utils.*;



include "../../../includes/loggerSnippet.as";


[Bindable]
public var model : LifeModelLocator = LifeModelLocator.getInstance();

[Bindable]
public var stats : StatsVO;

private function itemClicked( event : MenuEvent ) : void {
	//Alert.show( "[menu] data=" + event.item.@data );
	handleClick( event.item.@data );
}

private function handleClick( str : String ) : void{
	switch( str ){
		case 'normalCollect':
			( new ShowCollectEvent() ).dispatch();
			break;
		case 'quickCollect':
			( new ShowMiniCollectEvent(-1) ).dispatch();
			break;
		case 'imapImport':
			( new DoImapImportEvent() ).dispatch();
			break;
		case 'dashboard':
			( new ShowDashboardEvent() ).dispatch();
			break;						
		case 'stats':
			Alert.show('stats...');
			break;						
		case 'search':
			Alert.show('search...');
			break;		
		case 'normalProcess':
			( new ShowProcessEvent() ).dispatch();
			break;
		case 'organizeChecklist':
			( new ShowOrganizeEvent() ).dispatch();
			break;
		case 'projectTree':
			( new ShowOrganizeTreeEvent() ).dispatch();
			break;
		case 'projectList':
			( new ShowOrganizeListEvent() ).dispatch();
			break;
		case 'idleProjects':
			Alert.show('idleProjects');
			break;
		case 'udf':
			( new ShowOrganizeListEvent('udf') ).dispatch();
			break;
		case 'unf':
			( new ShowOrganizeListEvent('unf') ).dispatch();
			break;
		case 'wf':
			( new ShowOrganizeListEvent('wf') ).dispatch();
			break;
		case 'calendar':
			( new ShowOrganizeListEvent('calendar') ).dispatch();
			break;
		case 'dReview':
			( new ShowReviewEvent('daily') ).dispatch();
			break;
		case 'mReview':
			( new ShowReviewEvent('monthly') ).dispatch();
			break;
		case 'wReview':
			( new ShowReviewEvent('weekly') ).dispatch();
			break;
		case 'qReview':
			( new ShowReviewEvent('quarterly') ).dispatch();
			break;
		case 'yReview':
			( new ShowReviewEvent('yearly') ).dispatch();
			break;
		case 'atHome':
			( new ShowDoEvent( LifeModelLocator.CTX_HOME ) ).dispatch();
			break;
		case 'atWork':
			( new ShowDoEvent( LifeModelLocator.CTX_WORK ) ).dispatch();
			break;
		case 'atOnline':
			( new ShowDoEvent( LifeModelLocator.CTX_INTERNET ) ).dispatch();
			break;
		case 'calls':
			( new ShowDoEvent( LifeModelLocator.CTX_PHONE ) ).dispatch();
			break;
		case 'dueThisMonth':
			( new ShowDoEvent( LifeModelLocator.CTX_DUE_THIS_MONTH ) ).dispatch();
			break;
		case 'dueThisWeek':
			( new ShowDoEvent( LifeModelLocator.CTX_DUE_THIS_WEEK ) ).dispatch();
			break;
		case 'logout':
			Alert.show('logout...');
			break;
		case 'errands':
			( new ShowDoEvent( LifeModelLocator.CTX_ERRANDS ) ).dispatch();
			break;
		case 'allActions':
			( new ShowDoEvent( 0 ) ).dispatch();
			break;
		case 'appVersion':
			( new ShowVersionEvent() ).dispatch();
			break;
		case 'playerVersion':
			Alert.show( model.getPlayerString() );
			break;
		case 'osVersion':
			Alert.show( "OS: "+ Capabilities.os );
			break;
		case 'memoryUsage':
			var memUsageInKb : uint = Math.round( (System.totalMemory) / 1024 );
			var memUsageInMb : uint = Math.round( (System.totalMemory) / (1024*1024) );
			Alert.show( "Memory Usage: " + memUsageInKb + "-Kb\n(" + memUsageInMb + "-Mb)" );
			break;
		case 'doGarbageCollection':
			//Alert.show("...only available in flex 3");
			//log.warn('givon: fix garbage collection');
			System.gc();	//only in Flex 3
			break;
		case 'screenResolution':
			var s : String = Capabilities.screenResolutionX + " x " + Capabilities.screenResolutionY;
			s += "\n" + Capabilities.screenDPI + "-dpi"; 
			Alert.show(s);
			break;
		case 'avSupport':
			var s77 : String = "MP3 Support: " + Capabilities.hasMP3;
			s77 += "\nhasAudioEncoder: " + Capabilities.hasAudioEncoder;
			s77 += "\nhasAudio: " + Capabilities.hasAudio;
			s77 += "\nhasVideoEncoder: " + Capabilities.hasVideoEncoder;
			Alert.show(s77);
			break; 	
		default:
			Alert.show("Code Error: unhandled menu event: " + label);
	}
}
			
private function doInit(): void {
	myMenuBar.addEventListener( MenuEvent.ITEM_CLICK, itemClicked );
}
